<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="零售收银-挂单">
    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">

    <style>

    </style>

    <script>
        jQuery(function () {
            $(window).focus();
            window.addEventListener("keydown", function(e) {
                if (e.keyCode == 0x1B){
                    closeAllDialog();
                } else if (e.keyCode == 0x0D){
                    enter();
                }
                e.preventDefault();
            }, false);

            $(".esc").click(function () {
                closeAllDialog();
            });

            $(".enter").click(function () {
                enter();
            });
        });

        function enter() {
            console.log("挂单页面按确认件");
            post("${baseUrl}sale/retail/hangGoods.action",userHangVo, function (res) {
                if (res.code == 1) {
                    window.parent.hangSuccess();
                    closeAllDialog();
                }  else {
                    errTip(res.msg);
                    setTimeout(function () {
                        closeAllDialog();
                    },1000);
                }
            });
        }

        function closeAllDialog() {
            window.parent.closeAllDialog();
        }

        let userHangVo = {};
        function setGoodsList(goodsList, customId, discountFlag,discountInput) {
            userHangVo.customId = customId;
            userHangVo.discountFlag = discountFlag;
            if (userHangVo.discountFlag == "1") {
                userHangVo.discountRate = discountInput;
            } else {
                userHangVo.discountAmt = discountInput;
            }

            let userHangGoodsList = [];
            let userHangSnList = [];
            $.each(goodsList,function (i,d) {
                let vo = {};
                vo.goodsId = d.goodsId;
                vo.packetId = d.packetId;
                vo.unitId = d.unitId;
                vo.times = d.times;
                vo.price = d.price;
                vo.number = d.number;
                vo.amount = d.amount;
                vo.remark = d.remark;
                userHangGoodsList.push(vo);
                if (d.goodsSnList != undefined && d.goodsSnList.length > 0){
                    $.each(d.goodsSnList, function (j, goodsSn) {
                        userHangSnList.push({goodsId:goodsSn.goodsId,goodsSnId:goodsSn.id});
                    });
                }
            });

            userHangVo.userHangGoodsList = userHangGoodsList;
            userHangVo.userHangSnList = userHangSnList;
        }
    </script>
</html:header>
<body style="margin:0;background-color: #FFFFFF;height: 270px;width: 500px;padding-top: 30px;">
    <div style="margin: 0 auto;border-radius: 50%; width: 80px;height: 80px;line-height: 80px; background-color: #dddddd;text-align: center;">
        <i class="layui-icon layui-icon-help" style="color: #ffffff;font-size: 40px;"></i>
    </div>

    <div id="hang-tip-title" style="font-size: 24px;width: 100%; text-align: center;padding-top: 20px;">
        <c:choose>
            <c:when test="${exist==true}">
                是否继续挂单？
            </c:when>

            <c:otherwise>
                确定进行挂单操作吗？
            </c:otherwise>
        </c:choose>
    </div>
    <div id="hang-tip-tip" style="font-size: 16px;color:#999;padding: 10px 60px 20px 60px;">
        <c:if test="${exist==true}">
            您现在有一挂单未处理，再次挂单会将上一挂单删除。
        </c:if>
    </div>


    <div style="margin: 0 auto; width: 220px;">
        <button class="layui-btn layui-btn-normal enter">确定(Enter)</button>
        <button class="layui-btn layui-btn-primary esc">取消(Esc)</button>
    </div>
</body>

</html>